package com.digitalchina.lxnsy.activity.old;

import android.graphics.Paint;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.entity.CoinPresentVO;
import com.digitalchina.lxnsy.toolkit.FrescoUtil;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;
import com.digitalchina.lxnsy.toolkit.Utils;
import com.facebook.drawee.view.SimpleDraweeView;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2017/11/16 20:06
 * 修改备注：
 * ================================================
 */
public class CoinPresentDetailActivity extends BaseActivity {

    @Bind(R.id.coin_tv_title)
    TextView coinTvTitle;
    @Bind(R.id.coin_tv_num)
    TextView coinTvNum;
    @Bind(R.id.coin_tv_content)
    TextView coinTvContent;
    @Bind(R.id.coin_tv_price_bottom)
    TextView coinTvPriceBottom;
    @Bind(R.id.coin_tv_exchange)
    TextView coinTvExchange;
    @Bind(R.id.coin_sdv)
    SimpleDraweeView coinSdv;
    @Bind(R.id.tv_original_price)
    TextView tvOriginalPrice;
    @Bind(R.id.tv_sold_num)
    TextView tvSoldNum;
    @Bind(R.id.tv_limitation)
    TextView tvLimitation;

    private CoinPresentVO coinPresentVO;

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_coin_present_detail);
        setTitle("商品详情");
    }

    @Override
    public void initMember() {
        coinPresentVO = (CoinPresentVO) getIntent().getSerializableExtra("coinPresentVO");

        if (coinPresentVO == null)
            return;

        FrescoUtil.showImageMid(coinPresentVO.getImage() != null ? coinPresentVO.getImage() : "", coinSdv);
        coinTvTitle.setText(coinPresentVO.getName() + "");
        coinTvNum.setText("库存：" + coinPresentVO.getSurplusAmount());
        coinTvContent.setText(coinPresentVO.getIntroduce() + "");

        if (StringUtil.isStrEmpty(coinPresentVO.getActivityPrice())){
            tvOriginalPrice.setVisibility(View.GONE);
            coinTvPriceBottom.setText(coinPresentVO.getPrice() + "");
        }else{
            tvOriginalPrice.setText(coinPresentVO.getPrice() + "农币"); // 原价
            coinTvPriceBottom.setText(coinPresentVO.getActivityPrice() + ""); // 活动价
            tvOriginalPrice.setVisibility(View.VISIBLE);
            tvOriginalPrice.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG ); //中间横线
            tvOriginalPrice.getPaint().setAntiAlias(true);// 抗锯齿
        }

        String exchangeUserNum = coinPresentVO.getExchangeUserNum();
        if (StringUtil.isStrEmpty(exchangeUserNum))
            exchangeUserNum = "0";
        tvSoldNum.setText("已兑换：" + exchangeUserNum);
        if (StringUtil.isStrEmpty(coinPresentVO.getBuyLimitSign())||coinPresentVO.getBuyLimitSign().equals("0"))
            tvLimitation.setText("无限制兑换");
        else
            tvLimitation.setText("每人限制兑换" + coinPresentVO.getPerBuyLimitNum() + "个");

    }

    @Override
    public void addListener() {
        if (!Utils.isLogin(this)) {
            Utils.notLoginGoto(this);
            return;
        }

        if (coinPresentVO != null) {
            coinTvExchange.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    GotoUtil.gotoActivity(CoinPresentDetailActivity.this, CoinPresentSubmitActivity.class, "coinPresentVO", coinPresentVO);
                }
            });
        }
    }

    @Override
    public void setHandler() {

    }

    @Override
    public void callBack(Object object) {

    }

    @Override
    public void rightOnClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
